﻿Imports MySql.Data.MySqlClient

Public Class checkRooms
    Dim connString As String = "Server=localhost; User Id=root; Password=; Database=leximoore"
    Dim dr As MySqlDataReader
    Public Function checkRooms()
        Dim code As String = bookedOnlineForm.bookingCodeTxt.Text()

        Using SQLConnection As New MySqlConnection(connString)
            Using sqlCommand As New MySqlCommand()

                With sqlCommand
                    .CommandText = "SELECT no_room FROM reservation WHERE confirmation LIKE '" + "%" + code + "%" + "'"
                    .Connection = SQLConnection
                    .CommandType = CommandType.Text
                End With
                Try
                    SQLConnection.Open()
                    dr = sqlCommand.ExecuteReader()
                    While (dr.Read())
                        Return dr.GetString(0)
                    End While

                Catch ex As MySqlException
                    MessageBox.Show(ex.Message)
                    Console.ReadLine()
                Finally
                    SQLConnection.Close()
                End Try
            End Using
        End Using
    End Function

    Public Function checkRoomType()
        Dim code As String = bookedOnlineForm.bookingCodeTxt.Text()

        Using SQLConnection As New MySqlConnection(connString)
            Using sqlCommand As New MySqlCommand()

                With sqlCommand
                    .CommandText = "SELECT room_id FROM reservation WHERE confirmation LIKE '" + "%" + code + "%" + "'"
                    .Connection = SQLConnection
                    .CommandType = CommandType.Text
                End With
                Try
                    SQLConnection.Open()
                    dr = sqlCommand.ExecuteReader()
                    While (dr.Read())
                        Return dr.GetString(0)
                    End While

                Catch ex As MySqlException
                    MessageBox.Show(ex.Message)
                    Console.ReadLine()
                Finally
                    SQLConnection.Close()
                End Try
            End Using
        End Using
    End Function
End Class
